package com.jl.config;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

@ApiModel("返回结果")
public class BaseResponse<T> implements Serializable {
    private static final long serialVersionUID = 2354881465436907718L;
    private String code = "1";
    @ApiModelProperty(notes = "操作描述")
    private String msg = "success";
    @JSONField(serialize = false)
    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static BaseResponse success() {
        return new BaseResponse<>();
    }

    public static <T> BaseResponse<T> success(T object) {
        BaseResponse<T> objectBaseRespons = new BaseResponse<>();
        objectBaseRespons.setData(object);
        return objectBaseRespons;
    }

    public static BaseResponse error(String code, String msg) {
        BaseResponse vo = new BaseResponse();
        vo.setCode(code);
        vo.setMsg(msg);
        return vo;
    }

    public static BaseResponse ok(String code, String msg) {
        BaseResponse vo = new BaseResponse();
        vo.setCode(code);
        vo.setMsg(msg);
        return vo;
    }

    public static BaseResponse RRException(String code, String msg) {
        BaseResponse vo = new BaseResponse();
        vo.setCode(code);
        vo.setMsg(msg);
        return vo;
    }

    public boolean isSuccess() {
        if ("1".equals(this.code)) {
            return true;
        }
        return false;
    }
}
